#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *stack = NULL, N, M;
    while (scanf("%d%d", &N, &M) == 2)
    {
        stack = (int *)malloc(sizeof(int) * N);
        if (stack == NULL) //养成检查malloc返回值的习惯
            return 1;

        int top = 0, op, id;

        while (M--)
        {
            scanf("%d%d", &op, &id);
            if (op == 1 && top < N) {
                stack[top++] = id; //栈未满，入栈
            }
            else if (op == 2 && top > 0) {
                top--; //栈不空，出栈
            }
            else {
                /* 工程项目中应考虑例外情况，进行错误处理 */
            }
        }

        if (top <= 0)
            printf("NULL\n");
        else {
            while (top)
                printf("%d ", stack[--top]);
            printf("\n");
        }

        free(stack);
        stack = NULL; //养成释放空间后指针赋值NULL的习惯
    }
    return 0;
}
